package com.che.libcommon.api.page;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import com.che.libcommon.ui.adapter.SampleRecyclerViewAdapter;

public abstract class PageAdapterWrapper<T,VH extends RecyclerView.ViewHolder> extends
    SampleRecyclerViewAdapter<T,VH> {

  private Pagination<T> pagination;

  public PageAdapterWrapper(Pagination<T> pagination) {
    this.pagination = pagination;
  }

  public void setPagination(Pagination<T> pagination) {
    this.pagination = pagination;
  }

  @Override
  public final void onBindViewHolder(@NonNull VH holder, int position) {
    super.onBindViewHolder(holder, position);
    if(pagination != null){
      pagination.tryLoad(position);
    }
  }



  @Override
  public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
    super.onDetachedFromRecyclerView(recyclerView);
    if(pagination != null){
      pagination.release();
    }

  }
}
